<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Parichay.Domain"
                   namespace="Parichay.Domain.Security.Entity">
    <!--
        NOTE: lazy="false" was added to fix a problem with NHibernate 1.2 Beta 2 where the property
              Id is expected to be virtual. This seems to be because by default 1.2 assumes all objects
              are proxy-ready.
    -->
    <class name="User" table="aspnet_membershipuser" lazy="false">
        <!-- Primary key is auto-generated by the database's native method. -->
        <id name="Id">
            <generator class="native">
                <!-- Used for Oracle tests, does not affect MS SQL. -->
                <param name="sequence">User_Id_SEQ</param>
            </generator>
        </id>
        <property name="Name" />
        <property name="LoweredName" />
        <property name="Description" />
        <property name="Password" column="`Password`" />
        <property name="PasswordFormat" />
        <property name="PasswordSalt" />
        <property name="Email" />
        <property name="LoweredEmail" />
        <property name="PasswordQuestion" />
        <property name="PasswordAnswer" />
        <property name="Comments" />
        <property name="IsApproved" type="Parichay.Security.UserType.OneZeroType, Parichay.Security" />
        <property name="IsLockedOut" type="Parichay.Security.UserType.OneZeroType, Parichay.Security" />
        <property name="CreationDate" />
        <property name="LastActivityDate" />
        <property name="LastLoginDate" />
        <property name="LastLockedOutDate" />
        <property name="LastPasswordChangeDate" />
        <property name="FailedPasswordAttemptCount" column="FailedPwdAttemptCnt" />
        <property name="FailedPasswordAttemptWindowStart" column="FailedPwdAttemptWndStart" />
        <property name="FailedPasswordAnswerAttemptCount" column="FailedPwdAnsAttemptCnt" />
        <property name="FailedPasswordAnswerAttemptWindowStart" column="FailedPwdAnsAttemptWndStart" />
        <bag name="Applications" table="aspnet_applicationuser" cascade="none" lazy="false" inverse="false" fetch="join">
            <key column="UserId" />
            <many-to-many column="ApplicationId" class="Application" />
        </bag>
    </class>

    <!--
        Queries used for support of base provider logic, which is assumes relationships are for a single
        web application. Therefore, in cases where lists are the result they are assumed for a given
        application identifier.
    -->
    <query name="User.ById">
        <![CDATA[
             from User as user
            where user.Id = ?
        ]]>
    </query>
    <query name="User.ByLoweredName">
        <![CDATA[
             from User as user
            where user.LoweredName = ?
        ]]>
    </query>
    <query name="User.GetLoweredNameByLoweredEmail">
        <![CDATA[
            select user.LoweredName
              from User as user
             where user.LoweredEmail = ?
        ]]>
    </query>

    <!--
        Queries used for support of multi-web application implementations where a single management console
        is used for all managed applications. This allows for use of a single pool of users/roles for multiple
        applications.
    -->
    <query name="User.GetUsersOnline">
        <![CDATA[
              from User as user
             where user.LastActivityDate > ?
        ]]>
    </query>
    <query name="User.FindAll">
        <![CDATA[
              from User
        ]]>
    </query>
    <query name="User.FindAllByLoweredName">
        <![CDATA[
              from User as user
             where user.LoweredName like ?
        ]]>
    </query>
    <query name="User.FindAllByLoweredEmail">
        <![CDATA[
              from User as user
             where user.LoweredEmail like ?
        ]]>
    </query>
</hibernate-mapping>